use "C:\Users\Andy baker\OneDrive - UCB-O365\Data\World Values Survey\WVS 1981 2014\WVS_Longitudinal_1981_2014_stata_v2015_04_18.dta" , clear

*egen countryyearid=concat(S003 S002)

recode S025 (81998=3) (82002=3) (82008=3) (122002=4) (122013=4) (202005=2) (311997=3) (312008=3) (312011=3) (321984=1) (321991=1) (321995=1) (321999=1) (322006=1) (322013=1) (361981=2) (361995=2) (362005=2) (362012=2) (401990=2) (401999=2) (402008=2) (482014=4) (501996=6) (502002=6) (511997=3) (512008=3) (512011=3) (561981=2) (561990=2) (561999=2) (562009=2) (701998=3) (702001=3) (702008=3) (761991=1) (761997=1) (762006=1) (762014=1) (1001991=3) (1001997=3) (1001999=3) (1002005=3) (1002006=3) (1002008=3) (1011998=.) (1121990=3) (1121996=3) (1122000=3) (1122008=3) (1122011=3) (1241982=9) (1241990=9) (1242000=9) (1242006=9) (1521990=1) (1521996=1) (1522000=1) (1522006=1) (1522011=1) (1561990=8) (1561995=8) (1562001=8) (1562007=8) (1562012=8) (1581994=8) (1582006=8) (1582012=8) (1701997=1) (1701998=1) (1702005=1) (1702012=1) (1911996=3) (1911999=3) (1912008=3) (1962006=2) (1962008=2) (1962011=2) (1972008=2) (2031990=3) (2031991=3) (2031998=3) (2031999=3) (2032008=3) (2081981=2) (2081990=2) (2081999=2) (2082008=2) (2141996=1) (2182011=1) (2182013=1) (2221999=1) (2312007=5) (2331990=3) (2331996=3) (2331999=3) (2332008=3) (2332011=3) (2461981=2) (2461990=2) (2461996=2) (2462000=2) (2462005=2) (2462009=2) (2501981=2) (2501990=2) (2501999=2) (2502006=2) (2502008=2) (2681996=3) (2682008=3) (2682009=3) (2682014=3) (2752013=4) (2761981=2) (2761990=2) (2761997=2) (2761999=2) (2762006=2) (2762008=2) (2762013=2) (2882007=5) (2882012=5) (3001999=2) (3002008=2) (3202004=1) (3442005=8) (3442013=8) (3481982=3) (3481991=3) (3481998=3) (3481999=3) (3482008=3) (3482009=3) (3521984=2) (3521990=2) (3521999=2) (3522009=2) (3561990=6) (3561995=6) (3562001=6) (3562006=6) (3562012=6) (3562014=6) (3602001=7) (3602006=7) (3642000=4) (3642007=4) (3682004=4) (3682006=4) (3682012=4) (3721981=2) (3721990=2) (3721999=2) (3722008=2) (3762001=4) (3801981=2) (3801990=2) (3801999=2) (3802005=2) (3802009=2) (3921981=8) (3921990=8) (3921995=8) (3922000=8) (3922005=8) (3922010=8) (3982011=3) (4002001=4) (4002007=4) (4002014=4) (4101982=8) (4101990=8) (4101996=8) (4102001=8) (4102005=8) (4102010=8) (4142014=4) (4172003=3) (4172011=3) (4222013=4) (4281990=3) (4281996=3) (4281999=3) (4282008=3) (4342014=4) (4401990=3) (4401997=3) (4401999=3) (4402008=3) (4421999=2) (4422008=2) (4582006=7) (4582012=7) (4662007=5) (4701983=2) (4701991=2) (4701999=2) (4702008=2) (4841981=1) (4841990=1) (4841995=1) (4841996=1) (4842000=1) (4842005=1) (4842012=1) (4981995=3) (4981996=3) (4982002=3) (4982006=3) (4982008=3) (4992008=3) (5042001=4) (5042007=4) (5042011=4) (5281981=2) (5281990=2) (5281999=2) (5282006=2) (5282008=2) (5282012=2) (5541998=2) (5542004=2) (5542011=2) (5661990=5) (5661995=5) (5662000=5) (5662011=5) (5781982=2) (5781990=2) (5781996=2) (5782007=2) (5782008=2) (5861997=6) (5862001=6) (5862012=6) (6041996=1) (6042001=1) (6042006=1) (6042012=1) (6081996=7) (6082001=7) (6082012=7) (6161989=3) (6161990=3) (6161997=3) (6161999=3) (6162005=3) (6162008=3) (6162012=3) (6201990=2) (6201999=2) (6202008=2) (6301995=9) (6302001=9) (6342010=4) (6421993=3) (6421998=3) (6421999=3) (6422005=3) (6422008=3) (6422012=3) (6431990=3) (6431995=3) (6431999=3) (6432006=3) (6432008=3) (6432011=3) (6462007=5) (6462012=5) (6822003=4) (6882008=3) (7022002=7) (7022012=7) (7031990=3) (7031991=3) (7031998=3) (7031999=3) (7032008=3) (7042001=7) (7042006=7) (7051992=3) (7051995=3) (7051999=3) (7052005=3) (7052008=3) (7052011=3) (7101982=5) (7101990=5) (7101996=5) (7102001=5) (7102006=5) (7102013=5) (7162001=5) (7162012=5) (7241981=2) (7241990=2) (7241995=2) (7241999=2) (7242000=2) (7242007=2) (7242008=2) (7242011=2) (7521981=2) (7521982=2) (7521990=2) (7521996=2) (7521999=2) (7522006=2) (7522009=2) (7522011=2) (7561989=2) (7561996=2) (7562007=2) (7562008=2) (7642007=7) (7642013=7) (7802006=1) (7802011=1) (7882013=4) (7921990=4) (7921996=4) (7922001=4) (7922007=4) (7922009=4) (7922011=4) (8002001=5) (8041996=3) (8041999=3) (8042006=3) (8042008=3) (8042011=3) (8071998=3) (8072001=3) (8072008=3) (8182000=4) (8182001=4) (8182008=4) (8182013=4) (8261981=2) (8261990=2) (8261995=2) (8261998=2) (8261999=2) (8262005=2) (8262009=2) (8342001=5) (8401981=9) (8401982=9) (8401990=9) (8401995=9) (8401999=9) (8402006=9) (8402011=9) (8542007=5) (8581996=1) (8582006=1) (8582011=1) (8602011=3) (8621996=1) (8622000=1) (8872014=4) (8911996=3) (8912001=3) (8912005=3) (8942007=5) (9001997=2) (9002006=2) (9002013=2) (9011997=2) (9012006=2) (9012013=2) (9091981=2) (9091990=2) (9091999=2) (9092008=2) (9111996=3) (9112001=3) (9112006=3) (9121996=3) (9122001=3) (9141998=3) (9152008=3), gen(region)
label define region 1 "Latin America" 2 "Western Europe & Antipodes" 3 "Eastern Europe & Central Asia" 4 "Middle East & North Africa" 5 "Sub-Saharan Africa" 6 "South Asia" 7 "Southeast Asia" 8 "East Asia" 9 "North America"
label values region region

recode A062 -4/-1=. 3=0 2=1 1=2 
label drop A062
label define A062 2 Frequently 1 Occasionally 0 Never
label values A062 A062
tab A062

svyset [pweight=S018]
summ A062
svy: mean A062
estat sd

preserve
collapse (mean) A062 (min) S025 [pweight=S018], by(region)
drop if A062==.
sort A062
gen n=_n

*Figure 2.1A
graph bar (mean) A062, over(n, relabel(1 "MENA (11)" 2 "{bf:Lat Amer (21)}" 3 "North Amer (5)" 4 "South Asia (7)" 5 "SE Asia (5)" 6 "SS Africa (10)" 7 "E Asia (12)" 8 "W Europe (14)" 9 "E Europe (36)") label(ticks labs(medsmall) angle(vertical)))  ///
graphregion(color(white) margin(medlarge)) plotregion(lstyle(yxline) lcolor(black)) ytitle("{bf:Frequency of Political Discussion}" "{bf:with Friends}") yscale(range(0 2)) ylabel(0 "Never" 1 "Occasionally" 1.97 "Frequently", labsize(medsmall))   bar(1, color(black)) ///
yline(.8514, lcolor(black)) text(.92 6.5 "Global Mean", size(medsmall) color(black)) 
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Chapter 2 Description\Figures\WVSfreq.tif", as(tif) replace
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Publishers\Final Manuscript\Final Figures\BAR2_1A.tif", as(tif) replace width(1500)
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Publishers\Final Manuscript\Final Figures\BAR2_1A.pdf", as(pdf) replace 

restore

collapse (mean) A062 (min) region S003 [pweight=S017], by(S025)
drop if A062==.
drop if region~=1
tab S025
gen year=_n
recode year 1=1984 2=1991 3=1995 4=1999 5=1991 6=1990 7=1996 8=2000 9=1998 10=1996 11=1999 12=1981 13=1990 14=1995 15=1996 16=2000 17=1996 18=2001 19=1996 20=1996 21=2000
gen label="ARG" if S003==32
replace label="BRA" if S003==76
replace label="CHL" if S003==152
replace label="COL" if S003==170
replace label="DOM" if S003==214
replace label="SLV" if S003==222
replace label="MEX" if S003==484
replace label="PER" if S003==604
replace label="URY" if S003==858
replace label="VEN" if S003==862


twoway (scatter A062 year if S003==32, sort connect(l) lcolor(black) msym(i) mlab(label) mlabpos(0) mlabc(black) mlabsize(small)) ///
(scatter A062 year if S003==152, sort connect(l) lcolor(black) lcolor(black) msym(i) mlab(label) mlabpos(0) mlabc(black) mlabsize(small)) ///
(scatter A062 year if S003==484, sort connect(l) lcolor(black) lcolor(black) msym(i) mlab(label) mlabpos(0) mlabc(black) mlabsize(small)) ///
(scatter A062 year if S003==604, sort connect(l) lcolor(black) lcolor(black) msym(i) mlab(label) mlabpos(0) mlabc(black) mlabsize(small)) ///
(scatter A062 year if S003==862, sort connect(l) lcolor(black) lcolor(black) msym(i) mlab(label) mlabpos(0) mlabc(black) mlabsize(small)) ///
(scatter A062 year if S003==76 | S003==170 | S003==214 | S003==222 | S003==76 | S003==858, lcolor(black) msym(i) mlab(label) mlabpos(0) mlabc(black) mlabsize(small)), ///
graphregion(color(white) margin(medlarge)) plotregion(lstyle(yxline) lcolor(black)) legend(off) ///
ytitle("{bf:Frequency of Political Discussion}" "{bf:with Friends}")  xscale(range(1980 2002)) yscale(range(0 2)) ylabel(0 "Never" 1 "Occasionally" 1.97 "Frequently", labsize(medsmall))  ///
yline(.8514, lcolor(black)) text(.90 1981.6 "Global Mean", size(medsmall) color(black)) xtitle("{bf:Year}")
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Chapter 2 Description\Figures\WVSfreq2.tif", as(tif) replace
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Publishers\Final Manuscript\Final Figures\BAR2_1B.tif", as(tif) replace width(1500)
graph export "C:\Users\Andy baker\OneDrive - UCB-O365\My Documents\Research\Paper Book Networks\Publishers\Final Manuscript\Final Figures\BAR2_1B.pdf", as(pdf) replace 
